package cn.zh.service.impl;

import cn.zh.commons.ResponseResult;
import cn.zh.entity.Admin;
import cn.zh.entity.Order;
import cn.zh.mapper.OrderMapper;
import cn.zh.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author : 张航
 * @date : 2024-05-30 15:13
 * @description:
 **/
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;


    public ResponseResult orderPage(Integer page, Integer limit, String orderId) {
        PageHelper.startPage(page,limit);
        List<Order> orders= orderMapper.selectList(orderId);
        PageInfo<Order> orderPageInfo = new PageInfo<Order>(orders);
        long total = orderPageInfo.getTotal();
        System.out.println("total = " + total);

        return ResponseResult.success().data(orders).count(total);
    }


    public ResponseResult deleteOrder(Integer[] ids) {
        //判断删除的内容是否已回访
        List<Order> messages= orderMapper.selectOrderList(ids);
        if (!ObjectUtils.isEmpty(messages)){

            return ResponseResult.fail().message("删除的信息没有审核");
        }
        orderMapper.deleteOrder(ids);
        return ResponseResult.success().message("删除成功");
    }


    public ResponseResult editOrder(Integer id) {
        orderMapper.editOrder(id);
        return ResponseResult.success().message("通过处理");
    }


    public ResponseResult noEditOrder(Integer id) {
        orderMapper.noEditOrder(id);
        return ResponseResult.success().message("不通过处理");
    }


    public ResponseResult addOrder(Order order, HttpServletRequest request) {

        Admin admin =(Admin) request.getSession().getAttribute("admin");

        String username = admin.getUsername();
        order.setTenement(username);
        return null;

    }

}
